using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace Report.PhieuA
{
    public partial class UcA41 : DevExpress.XtraEditors.XtraUserControl
    {
        public UcA41()
        {
            InitializeComponent();
        }

        private void UcA41_Load(object sender, EventArgs e)
        {
            DataTable dtA41 = new DsReportX.Table2ColDataTable();
            dtA41 = CalculateData(dtA41);
            gridControlA.DataSource = dtA41;
        }

        DataTable CalculateData(DataTable dt)
        {
            SqlConnection con = new SqlConnection(GeneralLibs.LocalSettings.ConnectString);
            SqlCommand cmd = con.CreateCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                con.Open();
                cmd.CommandText = "SELECT * FROM ( \n" +
                                "	SELECT '1' TraLoi, COUNT(CauTraLoiFIX1) Number1 FROM Phieu A INNER JOIN ChiTietPhieu B ON A.ID = B.PhieuID  \n" +
                                "	WHERE A.LoaiPhieu IN('PhieuA') AND MaCau = 23 AND CauTraLoiFIX1 = 1  \n" +
                                ") DoanhNghiepCo, ( \n" +
                                "	SELECT COUNT(CauTraLoiFIX1) Number2 FROM Phieu A INNER JOIN ChiTietPhieu B ON A.ID = B.PhieuID  \n" +
                                "	WHERE A.LoaiPhieu IN('PhieuA') AND MaCau = 23 AND CauTraLoiFIX1 = 2 \n" +
                                ") DoanhNghiepKhong \n" +
                                "UNION  \n" +
                                "SELECT * FROM ( \n" +
                                "	SELECT '2' TraLoi, COUNT(CauTraLoiFIX1) Number1 FROM Phieu A INNER JOIN ChiTietPhieu B ON A.ID = B.PhieuID  \n" +
                                "	WHERE A.LoaiPhieu IN('PhieuB') AND MaCau = 18 AND CauTraLoiFIX1 = 1 \n" +
                                ") NLDCo, ( \n" +
                                "	SELECT COUNT(CauTraLoiFIX1) Number2 FROM Phieu A INNER JOIN ChiTietPhieu B ON A.ID = B.PhieuID  \n" +
                                "	WHERE A.LoaiPhieu IN('PhieuB') AND MaCau = 18 AND CauTraLoiFIX1 = 2 \n" +
                                ") NLDKhong";

                da.SelectCommand = cmd;
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
